﻿using Rechargeable.Games.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Rechargeable.Games
{
    public class GameAccountAppService : CrudAppService<
        GameAccount, GameAccountDto, Guid, PagedAndSortedResultRequestDto,
        CreateUpdateGameAccountDto,
        CreateUpdateGameAccountDto>, IGameAccountAppService
    {
        public GameAccountAppService(IRepository<GameAccount, Guid> repository) : base(repository)
        {

        }

        public override async Task<GameAccountDto> CreateAsync(CreateUpdateGameAccountDto input)
        {
            var gameAccount =(await Repository.GetQueryableAsync()).Where(q => q.LoginName == input.LoginName).FirstOrDefault();
            if (gameAccount != null)
            {
                return await UpdateAsync(gameAccount.Id, input);
            }
            return await base.CreateAsync(input);
        }
    }
}
